package com.huabo.contract.mysql.mapper;

import com.hbfk.util.PageInfo;
import com.huabo.contract.mysql.entity.TblCyhwEconomiccontractMySql;

import java.math.BigDecimal;

public class TblCyhwEconomiccontractMySqlMapperSqlConfig {


    public String findListByPageInfo(PageInfo<TblCyhwEconomiccontractMySql> pageInfo, BigDecimal orgid) throws Exception {
    	TblCyhwEconomiccontractMySql contract = new TblCyhwEconomiccontractMySql();
        StringBuffer sqlSb = new StringBuffer("SELECT * FROM (SELECT BUDGET.*,ROWNUM RN FROM (SELECT * from TBL_CYHW_ECONOMICCONTRACT where ORGID=" + orgid );

        if (contract.getContractno() != null && !"".equals(contract.getContractno())) {
            sqlSb.append( " AND contractNo LIKE '%" + (contract.getContractno() + "%'"));
        }

        if (contract.getFlowid() != null && !"".equals(contract.getFlowid())) {
            sqlSb.append( " and FLOWID=" + (contract.getFlowid()));
        }

        sqlSb.append("  ORDER BY CONTRACTID DESC ) BUDGET WHERE rownum <= "+(pageInfo.getCurrentPage()*pageInfo.getPageSize())+" ) WHERE RN > "+pageInfo.getCurrentRecord());
        String sql = sqlSb.toString();
        return sql;
    }


    public String findListByPageInfoCount(BigDecimal orgid) throws Exception {
    	TblCyhwEconomiccontractMySql contract = new TblCyhwEconomiccontractMySql();
        StringBuffer sqlSb = new StringBuffer("SELECT COUNT(*) from TBL_CYHW_ECONOMICCONTRACT where ORGID=" + orgid );

        if (contract.getContractno() != null && !"".equals(contract.getContractno())) {
            sqlSb.append( " AND contractNo LIKE '%" + (contract.getContractno() + "%'"));
        }

        if (contract.getFlowid() != null && !"".equals(contract.getFlowid())) {
            sqlSb.append( " and FLOWID=" + (contract.getFlowid()));
        }

        //sqlSb.append("  ORDER BY CONTRACTID DESC ) BUDGET WHERE rownum <= "+(pageInfo.getCurrentPage()*pageInfo.getPageSize())+" ) WHERE RN > "+pageInfo.getCurrentRecord());
        String sql = sqlSb.toString();
        return sql;
    }



    public String findListByPage(PageInfo<TblCyhwEconomiccontractMySql> pageInfo, String userid, BigDecimal orgid) throws Exception {
    	TblCyhwEconomiccontractMySql contract = new TblCyhwEconomiccontractMySql();
        StringBuffer sqlSb = new StringBuffer("SELECT * FROM (SELECT BUDGET.*,ROWNUM RN FROM (SELECT * from TBL_CYHW_ECONOMICCONTRACT where ORGID=" + orgid + "  and (CONTRACTID in (select FROMID from TBL_MY_TASK where USRID=" + userid + ") or CREATEUSER=" + userid   );

        if (contract.getContractno() != null && !"".equals(contract.getContractno())) {
            sqlSb.append( " AND contractNo LIKE '%" + (contract.getContractno() + "%'"));
        }

        if (contract.getFlowid() != null && !"".equals(contract.getFlowid())) {
            sqlSb.append( " and FLOWID=" + (contract.getFlowid()));
        }

        sqlSb.append(" ORDER BY CONTRACTID DESC ) BUDGET WHERE rownum <= "+(pageInfo.getCurrentPage()*pageInfo.getPageSize())+" ) WHERE RN > "+pageInfo.getCurrentRecord());
        String sql = sqlSb.toString();
        return sql;
    }


    public String findListByPageCount(String userid, BigDecimal orgid) throws Exception {
    	TblCyhwEconomiccontractMySql contract = new TblCyhwEconomiccontractMySql();
        StringBuffer sqlSb = new StringBuffer("SELECT COUNT(*) from TBL_CYHW_ECONOMICCONTRACT where ORGID=" + orgid + "  and (CONTRACTID in (select FROMID from TBL_MY_TASK where USRID=" + userid + ") or CREATEUSER=" + userid   );

        if (contract.getContractno() != null && !"".equals(contract.getContractno())) {
            sqlSb.append( " AND contractNo LIKE '%" + (contract.getContractno() + "%'"));
        }

        if (contract.getFlowid() != null && !"".equals(contract.getFlowid())) {
            sqlSb.append( " and FLOWID=" + (contract.getFlowid()));
        }

        //sqlSb.append(" ORDER BY CONTRACTID DESC ) BUDGET WHERE rownum <= "+(pageInfo.getCurrentPage()*pageInfo.getPageSize())+" ) WHERE RN > "+pageInfo.getCurrentRecord());
        String sql = sqlSb.toString();
        return sql;
    }
}
